/**
 * 
 */
package com.estock.platform.http.response;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.estock.common.model.security.RealTimeIndex;

/**
 * @author richard
 * 
 */
public class SinaRealTimeIndexBulkResponse extends SinaBaseResponse {

	List<RealTimeIndex> realTimeindexes = new ArrayList<RealTimeIndex>();
	public List<RealTimeIndex> getRealTimeindexes() {
		return realTimeindexes;
	}

	/**
	 * 	Returned string is not json format, it's something like
	 *	var hq_str_s_sh000010="上证180,10024.26,237.633,2.43,1777574,23076873";
	 *	var hq_str_s_sz399001="深证成指,13933.909,287.302,2.11,227674680,28603178";
	 * 
	 * @param sinaJsString
	 */
	@Override
	protected void parse(String sinaJsString) {
		parameters.clear();

		if (StringUtils.isEmpty(sinaJsString)) {
			throw new RuntimeException();
		}
		String[] tempArr = sinaJsString.split("=");
		String[] values = tempArr[1].replace("\"", "").split(",");
		
		RealTimeIndex realTimeIndex = new RealTimeIndex();
    	realTimeIndex.setCode(tempArr[0].substring(tempArr[0].length() - 6, tempArr[0].length()));
    	realTimeIndex.setDateTime(new Date());
    	realTimeIndex.setMarketIndex(Double.valueOf(values[1]));
    	realTimeIndex.setPrice(Double.valueOf(values[2]));
    	realTimeIndex.setIncreaseRate(Double.valueOf(values[3]));
    	realTimeIndex.setVolumeSum(Integer.valueOf(values[4]));
    	realTimeIndex.setTurnOver(Integer.valueOf(values[5]));

		realTimeindexes.add(realTimeIndex);
	}

}
